package com.crl.ssc.dic.dao;

import com.cars.util.page.PageUtil;
import com.cars.util.string.StringUtil;
import com.crl.dao.BaseDao;
import org.springframework.stereotype.Repository;
import java.util.List;
import com.crl.ssc.dic.model.DicPerson;
import com.crl.ssc.dic.vo.DicPersonSearchVO;


/**
 * @description: 字典管理-人员字典Dao
 * @author: MqSql
 * @version: 1.0
 * @date: 2020-08-05 00:32:29
 */
@Repository
public class DicPersonDao extends BaseDao<DicPerson, DicPersonSearchVO> {
    /**
     * 新增
     *
     * @param dicPerson
     * @return
     */
    public int add(DicPerson dicPerson) {
        String sql = "INSERT INTO td_dic_person(name,age,height,birth,create1,test) " +
                "VALUES(:name,:age,:height,:birth,:create1,:test)";
        return insert(sql, dicPerson);
    }

    /**
     * 修改
     *
     * @param dicPerson
     * @return
     */
    public int update(DicPerson dicPerson) {
        String sql = "UPDATE td_dic_person SET name=:name,age=:age,height=:height,birth=:birth,create1=:create1,test=:test " +
                    "WHERE id=:id";
        return update(sql, dicPerson);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    public int delete(Integer id) {
        String sql = "DELETE FROM td_dic_person WHERE id=?";
        return delete(sql, id);
    }
    /**
     * 列表
     *
     * @param dicPersonSearchVO
     * @return
     */
    public List<DicPerson> list(DicPersonSearchVO dicPersonSearchVO) {
        String sql = "SELECT id,name,age,height,birth,create1,test FROM td_dic_person WHERE 1=1 ";
        sql += createSearchSQL(dicPersonSearchVO);
        sql += " ORDER BY id ASC";
        sql = PageUtil.createMysqlPageSql(sql, dicPersonSearchVO.getPage());
        return list(sql, dicPersonSearchVO);
    }
    /**
     * 查询数据条数
     *
     * @param dicPersonSearchVO
     * @return
     */
    public int count(DicPersonSearchVO dicPersonSearchVO) {
        String sql = "SELECT COUNT(id) FROM td_dic_person WHERE 1=1 ";
        sql += createSearchSQL(dicPersonSearchVO);
        return count(sql, dicPersonSearchVO);
    }
    /**
       * 拼接查询条件
       *
       * @param dicPersonSearchVO
       * @return
    */
    private String createSearchSQL(DicPersonSearchVO dicPersonSearchVO) {
        String sql = "";
        if (StringUtil.isNotNullOrEmpty(dicPersonSearchVO.getName())) {
			sql += " AND name =:name ";
		}
        return sql;
    }

    /**
     * 获取单个
     *
     * @param id
     * @return
     */
    public DicPerson get(Integer id) {
        String sql = "SELECT id,name,age,height,birth,create1,test FROM td_dic_person WHERE id=?";
        return get(sql, id);
    }
}
